package com.xspace.android.xafcommon.db.dbsub;


import android.database.sqlite.SQLiteDatabase;

import com.xspace.android.xafcommon.appliction.BaseApplication;
import com.xspace.android.xafcommon.db.dbbiz.PreferencesDBBiz;

public class BaseDbMg {
    private static BaseDbMg instance = null;
    //	private static MyDBHelper db;
    private static MyDBHelper db;
    private QACSortDBBiz mSortDBBiz;
    //	private MAreaDB mAreaDBBiz;
    private DraftMsgDB mDraftDBBiz;
    private OfflineObjectDB offlineObjectDBBiz;
    private OfflineWorkLogDB offlineWorkLogDBBiz;
    private OfflineHtmlDB offlineHtmlDBBiz;
    private CacheBackLogDB offlinePedingItemDBBiz;
    private OfflineDataRecordDB offlineDataRecordDBBiz;
    private byte[] _lock = new byte[0];
    //	private TabHostDBBiz mTabHostDBBiz;
//	private ChannelBiz mChannelSql;
//	private HtmlImgBiz mHtmlImgSql;
//	private UpdateTimeBiz mUpdateTimeSql;
    private AppDownDBBiz mAppDownDBBiz;
    private AppMenusDBBiz mAppMenusDBBiz;
    private AppDBBiz mAppDBBiz;
    //	private CallRecordDBBiz mCallRecordDBBiz;
//	private TradeDBBiz mTradeDBBiz;
    private PreferencesDBBiz mPreferencesDBBiz;

    private AuditAppDBBiz mAuditAppDBBiz;
    private AudioMsgDb mAudioMsgDb;
    private FileMgDb mFileMgDb;
    private FileUploadDBBiz fileUploadDBBiz;
    private WorkTypeDBBiz workTypeDBBiz;
    private WorkFormDBBiz workFormDBBiz;
    private WorkServiceObjDBBiz workServiceObjDBBiz;

    public BaseDbMg() {
//		db = new MyDBHelper(MyApplication.mContext);
        db = new MyDBHelper(BaseApplication.mInstance);
    }

    public static void close() {
        if (db != null) {
            try {
                SQLiteDatabase db2 = db.getWritableDatabase();
                db2.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
            db = null;
        }
    }

    public static BaseDbMg getInstance() {
        if (instance == null) {
            instance = new BaseDbMg();
        }
        return instance;
    }

    public FileMgDb getFileMgDb() {
        synchronized (_lock) {
            if (mFileMgDb == null) {
                mFileMgDb = new FileMgDb(db);
            }
            return mFileMgDb;
        }
    }

    public WorkTypeDBBiz getWorkTypeDBBiz() {
        synchronized (_lock) {
            if (workTypeDBBiz == null) {
                workTypeDBBiz = new WorkTypeDBBiz(db);
            }
            return workTypeDBBiz;
        }
    }

    public WorkFormDBBiz getWorkFormDBBiz() {
        synchronized (_lock) {
            if (workFormDBBiz == null) {
                workFormDBBiz = new WorkFormDBBiz(db);
            }
            return workFormDBBiz;
        }
    }

    public WorkServiceObjDBBiz getWorkServiceObjDBBiz() {
        synchronized (_lock) {
            if (workServiceObjDBBiz == null) {
                workServiceObjDBBiz = new WorkServiceObjDBBiz(db);
            }
            return workServiceObjDBBiz;
        }
    }

    public AuditAppDBBiz getAuditAppDBBiz() {
        synchronized (_lock) {
            if (mAuditAppDBBiz == null) {
                mAuditAppDBBiz = new AuditAppDBBiz(db);
            }
            return mAuditAppDBBiz;
        }
    }

    public AppDownDBBiz getAppDownDBBiz() {
        synchronized (_lock) {
            if (mAppDownDBBiz == null) {
                mAppDownDBBiz = new AppDownDBBiz(db);
            }
            return mAppDownDBBiz;
        }
    }

    public AppDBBiz getAppDBBiz() {
        synchronized (_lock) {
            if (mAppDBBiz == null) {
                mAppDBBiz = new AppDBBiz(db);
            }
            return mAppDBBiz;
        }
    }

    public QACSortDBBiz getSortDBBiz() {
        synchronized (_lock) {
            if (mSortDBBiz == null) {
                mSortDBBiz = new QACSortDBBiz(db);
            }
            return mSortDBBiz;
        }
    }
//	public MAreaDB getAreaDBBiz() {
//		synchronized (_lock) {
//			if (mAreaDBBiz == null) {
//				mAreaDBBiz = new MAreaDB(db);
//			}
//			return mAreaDBBiz;
//		}
//	}

    /**
     * 获取草稿数据
     **/
    public DraftMsgDB getDraftDBBiz() {
        synchronized (_lock) {
            if (mDraftDBBiz == null) {
                mDraftDBBiz = new DraftMsgDB(db);
            }
            return mDraftDBBiz;
        }
    }

    public OfflineObjectDB getOfflineObjectDBBiz() {
        synchronized (_lock) {
            if (offlineObjectDBBiz == null) {
                offlineObjectDBBiz = new OfflineObjectDB(db);
            }
            return offlineObjectDBBiz;
        }
    }

    public OfflineDataRecordDB getOfflineDataRecordDBBiz() {
        synchronized (_lock) {
            if (offlineDataRecordDBBiz == null) {
                offlineDataRecordDBBiz = new OfflineDataRecordDB(db);
            }
            return offlineDataRecordDBBiz;
        }
    }

    public OfflineWorkLogDB getOfflineWorkLogDBBiz() {
        synchronized (_lock) {
            if (offlineWorkLogDBBiz == null) {
                offlineWorkLogDBBiz = new OfflineWorkLogDB(db);
            }
            return offlineWorkLogDBBiz;
        }
    }

    public OfflineHtmlDB getOfflineHtmlDBBiz() {
        synchronized (_lock) {
            if (offlineHtmlDBBiz == null) {
                offlineHtmlDBBiz = new OfflineHtmlDB(db);
            }
            return offlineHtmlDBBiz;
        }
    }

    public CacheBackLogDB getOfflinePedingItemDBBiz() {
        synchronized (_lock) {
            if (offlinePedingItemDBBiz == null) {
                offlinePedingItemDBBiz = new CacheBackLogDB(db);
            }
            return offlinePedingItemDBBiz;
        }
    }

    //
//	public TabHostDBBiz getTabHostDBBiz() {
//		synchronized (_lock) {
//			if (mTabHostDBBiz == null) {
//				mTabHostDBBiz = new TabHostDBBiz(db);
//			}
//			return mTabHostDBBiz;
//		}
//	}
//
//	public ChannelBiz getChannelSql() {
//		synchronized (_lock) {
//			if (mChannelSql == null) {
//				mChannelSql = new ChannelBiz(db);
//			}
//			return mChannelSql;
//		}
//	}
//
//	public HtmlImgBiz getHtmlImgSql() {
//		synchronized (_lock) {
//			if (mHtmlImgSql == null) {
//				mHtmlImgSql = new HtmlImgBiz(db);
//			}
//			return mHtmlImgSql;
//		}
//	}
//
//	public UpdateTimeBiz getUpdateTimeSql() {
//		synchronized (_lock) {
//
//			if (mUpdateTimeSql == null) {
//				mUpdateTimeSql = new UpdateTimeBiz(db);
//			}
//			return mUpdateTimeSql;
//		}
//	}
    public AppMenusDBBiz getAppMenusSql() {
        synchronized (_lock) {

            if (mAppMenusDBBiz == null) {
                mAppMenusDBBiz = new AppMenusDBBiz(db);
            }
            return mAppMenusDBBiz;
        }
    }
//	public CallRecordDBBiz getCallRecordSql() {
//		synchronized (_lock) {
//
//			if (mCallRecordDBBiz == null) {
//				mCallRecordDBBiz = new CallRecordDBBiz(db);
//			}
//			return mCallRecordDBBiz;
//		}
//	}

//	public TradeDBBiz getTradeDBBiz() {
//		synchronized (_lock) {
//
//			if (mTradeDBBiz == null) {
//				mTradeDBBiz = new TradeDBBiz(db);
//			}
//			return mTradeDBBiz;
//		}
//	}	

    public PreferencesDBBiz getPreferencesDBBiz() {
        synchronized (_lock) {

            if (mPreferencesDBBiz == null) {
                mPreferencesDBBiz = new PreferencesDBBiz(db);
            }
            return mPreferencesDBBiz;
        }
    }

    public AudioMsgDb getAudioMsgDb() {
        synchronized (_lock) {

            if (mAudioMsgDb == null) {
                mAudioMsgDb = new AudioMsgDb(db);
            }
            return mAudioMsgDb;
        }
    }

    public FileUploadDBBiz getFileUploadDBBiz() {
        synchronized (_lock) {
            if (fileUploadDBBiz == null) {
                fileUploadDBBiz = new FileUploadDBBiz(db);
            }
            return fileUploadDBBiz;
        }
    }
}
